home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0035_Change Number Base.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  637b  |  31 lines

  1. { Updated NUMBERS.SWG on November 2, 1993 }
  2.  
  3. {
  4. JOHN GUILLORY
  5.  
  6. > Can someone please show me how I would convert a base 10 number to base 36?
  7. }
  8.  
  9. Function BaseChange(Num, NewBase : Word) : String;
  10. Const
  11.   BaseChars : Array [0..36] of Char = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  12. Var
  13.   St : String;
  14. begin
  15.   St := '';
  16.   Repeat
  17.     St  := BaseChars[Num MOD NewBase] + St;
  18.     Num := Num Div NewBase;
  19.   Until Num = 0;
  20.   BaseChange := St;
  21. end;
  22.  
  23. {
  24. This will convert a number in Base10 (Stored in Orig) to any Base in the
  25. range of 2 through 36 (Please, no base-1's/0's)
  26. }
  27.  
  28. begin
  29.   Writeln(Basechange(33, 3));
  30. end.
  31.